home *** CD-ROM | disk | FTP | other *** search
/ Libris Britannia 4 / science library(b).zip / science library(b) / DTP / DTP_TEX / H067.ZIP / JEM2TEX.PAS < prev    next >
Pascal/Delphi Source File  |  1991-04-14  |  41KB  |  1,210 lines

  1. {$A-,B-,D-,E-,F-,I+,L-,N-,O-,R-,S-,V-}
  2. {Compile with Turbo-Pascal 5.0}
  3. Program Jem2TeX(Input,Output);
  4. {
  5.   This program translates a .JEM file into a .TeX file
  6.  
  7.   Author: Francois Jalbert
  8.               '
  9.   Date: November 1990 
  10.  
  11.   Version: 1.0
  12.  
  13.   Date: January 1991
  14.  
  15.   Version: 1.01
  16.  
  17.   Modifications: - Added \hskip0pt plus0.1em between all Japanese symbols which 
  18.                    improved dramatically line breaks and inter-sentence spacing 
  19.                    since [La]TeX could only add glue between whole Japanese 
  20.                    sentences. 
  21.                  - Extra space after punctuation is now an option since it is 
  22.                    not desirable with MuTeX when the text is to go under the
  23.                    staff. 
  24.                  - Font names now use only small letters to be compatible with 
  25.                    the fontlib program supplied with emTeX. 
  26.                  - Command line parameters now supported.
  27.                  - Run-time parameters now supported.
  28.                  - Updated and improved run-time messages.
  29.  
  30.   Date: April 1991
  31.  
  32.   Version: 2.00
  33.  
  34.   Modifications: - Added four kanjis.
  35.                  - If desired, only standard JIS '83 characters are allowed.
  36.                  - If desired, a % is added at each Japanese end of line.
  37.                  - Three file name extensions .JEM .JPN .JAP now supported.
  38.                  - Default extension is .JEM and the program has been renamed.
  39.                  - Three run-time parameter flags now supported.
  40.                  - Japanese comments not translated anymore for reference.
  41.                  - Hyphenation and glue handled separately for better control.
  42.                  - More clever algorithm for Japanese hyphenation.
  43.                  - Space after some punctuation now obtained with \eeee.
  44.                  - Small space around some punctuation introduced with \eee.
  45.                  - Tiny space between Japanese characters with \ee.
  46.                  - Space between Japanese and Roman with \eeee and \eee.
  47.                  - Symbols separated only by [La]TeX comments are now 
  48.                    recognized as consecutive.
  49.                  - MS-kanji (Shift-JIS) now supported.
  50.  
  51.   Error Levels: 0 - Normal termination.
  52.                 1 - Error.
  53. }
  54. Const
  55.   {Highest Bitmap number in JIS24}
  56.   BitmapMax=7806;
  57.   {Highest font number}
  58.   FontMax=60; {Floor of 7806 Div 128}
  59.   {Highest size number}
  60.   SizeMax=7; {magsteps are 0, 0.5, 1, 2, 3, 4, 5}
  61.   {File name extensions in priority order}
  62.   Extension1:String[4]='.jem';
  63.   Extension2:String[4]='.jpn';
  64.   Extension3:String[4]='.jap';
  65.   {Run-time flag of all the same length}
  66.   RunFlag1:String[7]='JEM2TEX';
  67.   RunFlag2:String[7]='JPN2TEX';
  68.   RunFlag3:String[7]='JAP2TEX';
  69.   {Parameter flag}
  70.   Flag1='/'; {DOS style}
  71.   Flag2='-'; {UNIX style}
  72.   {Parameter keywords in approximate decreasing length order}
  73.   Space1:String[10]='EXTRASPACE';
  74.   Space2:String[5]='EXTRA';
  75.   Space3:String[5]='SPACE';
  76.   NoSpace1:String[12]='NOEXTRASPACE';
  77.   NoSpace2:String[7]='NOEXTRA';
  78.   NoSpace3:String[7]='NOSPACE';
  79.   Percent1:String[7]='COMMENT';
  80.   Percent2:String[7]='PERCENT';
  81.   Percent3:String[3]='EOL';
  82.   NoPercent1:String[9]='NOCOMMENT';
  83.   NoPercent2:String[9]='NOPERCENT';
  84.   NoPercent3:String[5]='NOEOL';
  85.   EUC1:String[3]='EUC';
  86.   NoEUC1:String[7]='MSKANJI';
  87.   NoEUC2:String[8]='SHIFTJIS';
  88.   Extended1:String[8]='EXTENDED';
  89.   Standard1:String[8]='STANDARD';
  90.   LaTeX1:String[5]='LATEX';
  91.   TeX1:String[5]='MUTEX';
  92.   TeX2:String[3]='TEX';
  93.   One1:String[4]='1000';
  94.   Two1:String[4]='1095';
  95.   Three1:String[4]='1200';
  96.   Four1:String[4]='1440';
  97.   Five1:String[4]='1728';
  98.   Six1:String[4]='2074';
  99.   Seven1:String[4]='2488';
  100.   One2:String[3]='0.0';
  101.   Two2:String[3]='0.5';
  102.   Three2:String[3]='1.0';
  103.   Four2:String[3]='2.0';
  104.   Five2:String[3]='3.0';
  105.   Six2:String[3]='4.0';
  106.   Seven2:String[3]='5.0';
  107.   One3:String[1]='0';
  108.   Three3:String[1]='1';
  109.   Four3:String[1]='2';
  110.   Five3:String[1]='3';
  111.   Six3:String[1]='4';
  112.   Seven3:String[1]='5';
  113.  
  114. Type
  115.   InFileType=File Of Byte;
  116.   OutFileType=Text;
  117.   BitmapRange=1..BitmapMax;
  118.   FontRange=0..FontMax;
  119.   FontType=Array [FontRange] Of Boolean;
  120.   SizeRange=1..SizeMax;
  121.   FontsType=Array [SizeRange] Of FontType;
  122.   {Run time parameters}
  123.   RunTimeType=Record
  124.                 FileName,Extension:String;
  125.                 ExtraSpace,Percent,LaTeX,EUC,Extended:Boolean;
  126.                 Size:SizeRange;
  127.               End;
  128.   {Japanese punctuation information}
  129.   PunctuationType=Record
  130.                     {Indicates .,!? present}
  131.                     OldMajorEOL,NewMajorEOL:Boolean;
  132.                     {Indicates :; present}
  133.                     OldMinorEOL,NewMinorEOL:Boolean;
  134.                     {Indicates `"([< and other openings present}
  135.                     OldOpening,NewOpening:Boolean;
  136.                     {Indicates '")]> and other closings present}
  137.                     OldClosing,NewClosing:Boolean;
  138.                     {Indicates Japanese center dot present}
  139.                     OldCenterDot,NewCenterDot:Boolean;
  140.                     {Indicates Hiragana, Katakana, or Kanji present}
  141.                     OldJapanese,NewJapanese:Boolean
  142.                   End;
  143.   {Scanning Information}
  144.   ScanningType=Record
  145.                  {Current pass terminated}
  146.                  Done:Boolean;
  147.                  {Indicates the current pass must produce output}
  148.                  Echo:Boolean;
  149.                  {Indicates the current line is a comment}
  150.                  Comment:Boolean;
  151.                  {Indicates current Bitmap immediately followed previous one}
  152.                  Immediate:Boolean;
  153.                  {Indicates the last Roman character was a letter or digit}
  154.                  WasLetter:Boolean;
  155.                  {Used for glue after a bitmap and before a roman}
  156.                  RomanMajorEOL,RomanMinorEOL,RomanOpening:Boolean;
  157.                  {Non-comment Bitmap found}
  158.                  Found:Boolean;
  159.                  {Processing the first character on the line which could be %}
  160.                  First:Boolean;
  161.                  {Comment line which may contain Bitmaps}
  162.                  CommentLine:String;
  163.                  {Current JIS24 Bitmap number}
  164.                  Bitmap:BitmapRange;
  165.                  {Roman or first part of Bitmap read}
  166.                  Data1:Byte
  167.                End;
  168.  
  169. Var
  170.   {Input and Output file names}
  171.   InFile:InFileType;
  172.   OutFile:OutFileType;
  173.   {Run time parameters}
  174.   RunTime:RunTimeType;
  175.   {JemTeX fonts used}
  176.   Fonts:FontsType;
  177.  
  178. {------------------------------ EchoParameters -------------------------------}
  179.  
  180. Procedure EchoParameters(Var EchoFile:Text; Var RunTime:RunTimeType);
  181. {Echoes the current parameters in EchoFile}
  182. Begin
  183. With RunTime Do
  184.   Begin
  185.   Write(EchoFile,'File='+FileName);
  186.   If ExtraSpace Then Write(EchoFile,'  Space')
  187.   Else Write(EchoFile,'  No Space');
  188.   If Percent Then Write(EchoFile,'  Added %')
  189.   Else Write(EchoFile,'  No Added %');
  190.   If LaTeX Then Write(EchoFile,'  LaTeX')
  191.   Else Write(EchoFile,'  TeX');
  192.   If EUC Then Write(EchoFile,'  EUC')
  193.   Else Write(EchoFile,'  MS-kanji');
  194.   If Extended Then Write(EchoFile,'  Extended')
  195.   Else Write(EchoFile,'  Standard');
  196.   Write(EchoFile,'  Font Size=');
  197.   Case Size Of
  198.     1:Write(EchoFile,'1000');
  199.     2:Write(EchoFile,'1095');
  200.     3:Write(EchoFile,'1200');
  201.     4:Write(EchoFile,'1440');
  202.     5:Write(EchoFile,'1728');
  203.     6:Write(EchoFile,'2074');
  204.     7:Write(EchoFile,'2488')
  205.     End;
  206.   Writeln(EchoFile,'.')
  207.   End
  208. End;
  209.  
  210. {------------------------------- GetParameters -------------------------------}
  211.  
  212. Procedure SimpleQuery(Title,ChoiceA,ChoiceB:String; Var Answer:Boolean);
  213. Var
  214.   JChar:Char;
  215.   Valid:Boolean;
  216. Begin
  217. Repeat
  218.   Valid:=True;
  219.   Writeln(Title+':');
  220.   Writeln('   a)  '+ChoiceA);
  221.   Writeln('   b)  '+ChoiceB);
  222.   Write('Your choice? ');
  223.   Readln(JChar);
  224.   JChar:=UpCase(JChar);
  225.   If JChar='A' Then Answer:=True
  226.   Else
  227.     If JChar='B' Then Answer:=False
  228.     Else
  229.       Begin Valid:=False; Write(Chr(7)) End
  230. Until Valid;
  231. Writeln
  232. End;
  233.  
  234. Procedure SizeQuery(Var Size:SizeRange);
  235. Var
  236.   JChar:Char;
  237.   Valid:Boolean;
  238. Begin
  239. Repeat
  240.   Valid:=True;
  241.   Writeln('Japanese Font Size:');
  242.   Writeln('   a)  1000  magstep(0.0)');
  243.   Writeln('   b)  1095  magstep(0.5)');
  244.   Writeln('   c)  1200  magstep(1.0)');
  245.   Writeln('   d)  1440  magstep(2.0)');
  246.   Writeln('   e)  1728  magstep(3.0)');
  247.   Writeln('   f)  2074  magstep(4.5)');
  248.   Writeln('   g)  2488  magstep(5.0)');
  249.   Write('Your choice? ');
  250.   Readln(JChar);
  251.   JChar:=UpCase(JChar);
  252.   If ('A'<=JChar) And (JChar<='G') Then
  253.     Size:=Ord(JChar)-Ord('A')+1
  254.   Else 
  255.     Begin Valid:=False; Write(Chr(7)) End
  256. Until Valid;
  257. Writeln
  258. End;
  259.  
  260. Procedure Manual(Var RunTime:RunTimeType);
  261. {Get parameters from user}
  262. Begin
  263. With RunTime Do
  264.   Begin
  265.   Write('Japanese file name? ');
  266.   Readln(FileName);
  267.   Writeln;
  268.  SimpleQuery('Space around Japanese punctuation','Space','No space',ExtraSpace);
  269.  SimpleQuery('Added % at Japanese end of lines','Added %','No added %',Percent);
  270.   SimpleQuery('LaTeX or TeX (MuTeX) output','LaTeX','TeX',LaTeX);
  271.   SimpleQuery('EUC or MS-kanji (Shift-JIS) encoding','EUC','MS-kanji',EUC);
  272. SimpleQuery('Extended JIS ''83 Bitmaps allowed','Extended','Standard',Extended);
  273.   SizeQuery(Size)
  274.   End
  275. End;
  276.  
  277. Procedure Automate(Var RunTime:RunTimeType);
  278. {Get parameters from command line}
  279. Var
  280.   ParamIndex,Index:Integer;
  281.   Param:String;
  282. Begin
  283. With RunTime Do
  284.   Begin
  285.   {Defaults}
  286.   FileName:='japanese';
  287.   ExtraSpace:=True;
  288.   Percent:=True;
  289.   LaTeX:=True;
  290.   EUC:=True;
  291.   Extended:=True;
  292.   Size:=4;
  293.   {Scan command line parameters}
  294.   For ParamIndex:=1 To ParamCount Do
  295.     Begin
  296.     Param:=ParamStr(ParamIndex);
  297.     If (Param[1]=Flag1) Or (Param[1]=Flag2) Then
  298.       {Not a filename}
  299.       Begin
  300.       {Delete 1 char at the 1st position}
  301.       Delete(Param,1,1);
  302.       {Convert to upper case}
  303.       For Index:=1 To Length(Param) Do Param[Index]:=UpCase(Param[Index]);
  304.       {Scan known keywords}
  305.       If (Param=Space1) Or (Param=Space2) Or (Param=Space3)Then ExtraSpace:=True
  306.       Else
  307.       If (Param=NoSpace1) Or (Param=NoSpace2) Or (Param=NoSpace3) Then
  308.         ExtraSpace:=False
  309.       Else
  310.       If (Param=Percent1) Or (Param=Percent2) Or (Param=Percent3) Then 
  311.         Percent:=True
  312.       Else
  313.       If (Param=NoPercent1) Or (Param=NoPercent2) Or (Param=NoPercent3) Then
  314.         Percent:=False
  315.       Else
  316.       If Param=EUC1 Then EUC:=True
  317.       Else
  318.       If (Param=NoEUC1) Or (Param=NoEUC2) Then EUC:=False
  319.       Else
  320.       If Param=Extended1 Then Extended:=True
  321.       Else
  322.       If Param=Standard1 Then Extended:=False
  323.       Else
  324.       If Param=LaTeX1 Then LaTeX:=True
  325.       Else
  326.       If (Param=TeX1) Or (Param=TeX2) Then LaTeX:=False
  327.       Else
  328.       If (Param=One1) Or (Param=One2) Or (Param=One3) Then Size:=1
  329.       Else
  330.       If (Param=Two1) Or (Param=Two2) Then Size:=2
  331.       Else
  332.       If (Param=Three1) Or (Param=Three2) Or (Param=Three3) Then Size:=3
  333.       Else
  334.       If (Param=Four1) Or (Param=Four2) Or (Param=Four3) Then Size:=4
  335.       Else
  336.       If (Param=Five1) Or (Param=Five2) Or (Param=Five3) Then Size:=5
  337.       Else
  338.       If (Param=Six1) Or (Param=Six2) Or (Param=Six3) Then Size:=6
  339.       Else
  340.       If (Param=Seven1) Or (Param=Seven2) Or (Param=Seven3) Then Size:=7
  341.       Else
  342.         {Unknown keyword}
  343.         Begin
  344.         Writeln(Chr(7)+'Invalid command line parameter: '+Param+'...');
  345.         Halt(1)
  346.         End
  347.       End
  348.     Else
  349.       {Must be a filename, we'll try to open it later}
  350.       FileName:=Param
  351.     End
  352.   End
  353. End;
  354.  
  355. Procedure GetParameters(Var RunTime:RunTimeType);
  356. {Get parameters from user or command line}
  357. {Current parameter status is echoed on the console}
  358. Begin
  359. If ParamCount=0 Then Manual(RunTime)
  360. Else Automate(RunTime);
  361. EchoParameters(Output,RunTime)
  362. End;
  363.  
  364. {-------------------------------- OpenFile -----------------------------------}
  365.  
  366. Function TryExtension(Var InFile:InFileType; Var RunTime:RunTimeType;
  367.                       TriedExtension:String):Boolean;
  368. {Tries to open FileName using TriedExtension}
  369. Begin
  370. With RunTime Do
  371.   Begin
  372.   Extension:=TriedExtension;
  373.   Assign(InFile,FileName+TriedExtension);
  374.   {$I-}Reset(InFile);{$I+}
  375.   {IOResult must be immediately used once only}
  376.   TryExtension:=(IOResult=0)
  377.   End
  378. End;
  379.  
  380. Procedure OpenFile(Var InFile:InFileType; Var RunTime:RunTimeType);
  381. {Tries to open FileName using all available extensions}
  382. Begin
  383. If TryExtension(InFile,RunTime,Extension1) Then Write(Extension1)
  384. Else
  385.   If TryExtension(InFile,RunTime,Extension2) Then Write(Extension2)
  386.   Else
  387.     If TryExtension(InFile,RunTime,Extension3) Then Write(Extension3)
  388.     Else
  389.       Begin
  390.       Writeln('.');
  391.       Writeln(Chr(7)+'File not found'+'...');
  392.       Halt(1)
  393.       End
  394. End;
  395.  
  396. {-------------------------------- GetBitmap ----------------------------------}
  397.  
  398. Procedure PerformScan(Var CommentLine:String; Var RunTime:RunTimeType;
  399.                       Echo:Boolean; Var OutFile:OutFileType); 
  400. {Scans the comment line for run-time JEM2TEX parameters}
  401. {Any Bitmap or unknown parameter stops the scan}
  402. {Current parameter status is echoed in the .TeX file as a [La]TeX comment}
  403. Var Index:Integer;
  404. Begin
  405. {Delete 1 char at the 1st position which is %}
  406. Delete(CommentLine,1,1);
  407. {Convert to upper case}
  408. For Index:=1 To Length(CommentLine) Do
  409.   CommentLine[Index]:=UpCase(CommentLine[Index]);
  410. {Add space at the line end to characterize premature termination}
  411. {Add sentinel at the line end to stop forthcoming loops}
  412. CommentLine:=CommentLine+' %';
  413. {Delete leading blanks}
  414. If CommentLine[1]=' ' Then 
  415.   Repeat Delete(CommentLine,1,1)
  416.   Until CommentLine[1]<>' '; 
  417. {Look for run-time flag at the start of line}
  418. If ( RunFlag1=Copy(CommentLine,1,Length(RunFlag1)) ) Or
  419.    ( RunFlag2=Copy(CommentLine,1,Length(RunFlag1)) ) Or
  420.    ( RunFlag3=Copy(CommentLine,1,Length(RunFlag1)) )
  421. Then
  422.   Begin
  423.   {Remove run-time flag}
  424.   Delete(CommentLine,1,Length(RunFlag1));
  425.   {Scan until sentinel reached}
  426.   Repeat
  427.     {Delete leading blanks}
  428.     If CommentLine[1]=' ' Then 
  429.       Repeat Delete(CommentLine,1,1)
  430.       Until CommentLine[1]<>' '; 
  431.     If (CommentLine[1]=Flag1) Or (CommentLine[1]=Flag2) Then
  432.       {Valid run-time parameter flag}
  433.       Begin
  434.       {Delete 1 char at the 1st position which is flag}
  435.       Delete(CommentLine,1,1);
  436.       {Scan in decreasing length order}
  437.       With RunTime Do
  438.         Begin
  439.         If Space1=Copy(CommentLine,1,Length(Space1)) Then
  440.           Begin Delete(CommentLine,1,Length(Space1)); ExtraSpace:=True End
  441.         Else
  442.         If Space2=Copy(CommentLine,1,Length(Space2)) Then
  443.           Begin Delete(CommentLine,1,Length(Space2)); ExtraSpace:=True End
  444.         Else
  445.         If Space3=Copy(CommentLine,1,Length(Space3)) Then
  446.           Begin Delete(CommentLine,1,Length(Space3)); ExtraSpace:=True End
  447.         Else
  448.         If NoSpace1=Copy(CommentLine,1,Length(NoSpace1)) Then
  449.           Begin Delete(CommentLine,1,Length(NoSpace1)); ExtraSpace:=False End
  450.         Else
  451.         If NoSpace2=Copy(CommentLine,1,Length(NoSpace2)) Then
  452.           Begin Delete(CommentLine,1,Length(NoSpace2)); ExtraSpace:=False End
  453.         Else
  454.         If NoSpace3=Copy(CommentLine,1,Length(NoSpace3)) Then
  455.           Begin Delete(CommentLine,1,Length(NoSpace3)); ExtraSpace:=False End
  456.         Else
  457.         If Percent1=Copy(CommentLine,1,Length(Percent1)) Then
  458.           Begin Delete(CommentLine,1,Length(Percent1)); Percent:=True End
  459.         Else
  460.         If Percent2=Copy(CommentLine,1,Length(Percent2)) Then
  461.           Begin Delete(CommentLine,1,Length(Percent2)); Percent:=True End
  462.         Else
  463.         If Percent3=Copy(CommentLine,1,Length(Percent3)) Then
  464.           Begin Delete(CommentLine,1,Length(Percent3)); Percent:=True End
  465.         Else
  466.         If NoPercent1=Copy(CommentLine,1,Length(NoPercent1)) Then
  467.           Begin Delete(CommentLine,1,Length(NoPercent1)); Percent:=False End
  468.         Else
  469.         If NoPercent2=Copy(CommentLine,1,Length(NoPercent2)) Then
  470.           Begin Delete(CommentLine,1,Length(NoPercent2)); Percent:=False End
  471.         Else
  472.         If NoPercent3=Copy(CommentLine,1,Length(NoPercent3)) Then
  473.           Begin Delete(CommentLine,1,Length(NoPercent3)); Percent:=False End
  474.         Else
  475.         If EUC1=Copy(CommentLine,1,Length(EUC1)) Then
  476.           Begin Delete(CommentLine,1,Length(EUC1)); EUC:=True End
  477.         Else
  478.         If NoEUC1=Copy(CommentLine,1,Length(NoEUC1)) Then
  479.           Begin Delete(CommentLine,1,Length(NoEUC1)); EUC:=False End
  480.         Else
  481.         If NoEUC2=Copy(CommentLine,1,Length(NoEUC2)) Then
  482.           Begin Delete(CommentLine,1,Length(NoEUC2)); EUC:=False End
  483.         Else
  484.         If Extended1=Copy(CommentLine,1,Length(Extended1)) Then
  485.           Begin Delete(CommentLine,1,Length(Extended1)); Extended:=True End
  486.         Else
  487.         If Standard1=Copy(CommentLine,1,Length(Standard1)) Then
  488.           Begin Delete(CommentLine,1,Length(Standard1)); Extended:=False End
  489.         Else
  490.         If LaTeX1=Copy(CommentLine,1,Length(LaTeX1)) Then
  491.           Begin Delete(CommentLine,1,Length(LaTeX1)); LaTeX:=True End
  492.         Else
  493.         If TeX1=Copy(CommentLine,1,Length(TeX1)) Then
  494.           Begin Delete(CommentLine,1,Length(TeX1)); LaTeX:=False End
  495.         Else
  496.         If TeX2=Copy(CommentLine,1,Length(TeX2)) Then
  497.           Begin Delete(CommentLine,1,Length(TeX2)); LaTeX:=False End
  498.         Else
  499.         If One1=Copy(CommentLine,1,Length(One1)) Then
  500.           Begin Delete(CommentLine,1,Length(One1)); Size:=1 End
  501.         Else
  502.         If Two1=Copy(CommentLine,1,Length(Two1)) Then
  503.           Begin Delete(CommentLine,1,Length(Two1)); Size:=2 End
  504.         Else
  505.         If Three1=Copy(CommentLine,1,Length(Three1)) Then
  506.           Begin Delete(CommentLine,1,Length(Three1)); Size:=3 End
  507.         Else
  508.         If Four1=Copy(CommentLine,1,Length(Four1)) Then
  509.           Begin Delete(CommentLine,1,Length(Four1)); Size:=4 End
  510.         Else
  511.         If Five1=Copy(CommentLine,1,Length(Five1)) Then
  512.           Begin Delete(CommentLine,1,Length(Five1)); Size:=5 End
  513.         Else
  514.         If Six1=Copy(CommentLine,1,Length(Six1)) Then
  515.           Begin Delete(CommentLine,1,Length(Six1)); Size:=6 End
  516.         Else
  517.         If Seven1=Copy(CommentLine,1,Length(Seven1)) Then
  518.           Begin Delete(CommentLine,1,Length(Seven1)); Size:=7 End
  519.         Else
  520.         If One2=Copy(CommentLine,1,Length(One2)) Then
  521.           Begin Delete(CommentLine,1,Length(One2)); Size:=1 End
  522.         Else
  523.         If Two2=Copy(CommentLine,1,Length(Two2)) Then
  524.           Begin Delete(CommentLine,1,Length(Two2)); Size:=2 End
  525.         Else
  526.         If Three2=Copy(CommentLine,1,Length(Three2)) Then
  527.           Begin Delete(CommentLine,1,Length(Three2)); Size:=3 End
  528.         Else
  529.         If Four2=Copy(CommentLine,1,Length(Four2)) Then
  530.           Begin Delete(CommentLine,1,Length(Four2)); Size:=4 End
  531.         Else
  532.         If Five2=Copy(CommentLine,1,Length(Five2)) Then
  533.           Begin Delete(CommentLine,1,Length(Five2)); Size:=5 End
  534.         Else
  535.         If Six2=Copy(CommentLine,1,Length(Six2)) Then
  536.           Begin Delete(CommentLine,1,Length(Six2)); Size:=6 End
  537.         Else
  538.         If Seven2=Copy(CommentLine,1,Length(Seven2)) Then
  539.           Begin Delete(CommentLine,1,Length(Seven2)); Size:=7 End
  540.         Else
  541.         If One3=Copy(CommentLine,1,Length(One3)) Then
  542.           Begin Delete(CommentLine,1,Length(One3)); Size:=1 End
  543.         Else
  544.         If Three3=Copy(CommentLine,1,Length(Three3)) Then
  545.           Begin Delete(CommentLine,1,Length(Three3)); Size:=3 End
  546.         Else
  547.         If Four3=Copy(CommentLine,1,Length(Four3)) Then
  548.           Begin Delete(CommentLine,1,Length(Four3)); Size:=4 End
  549.         Else
  550.         If Five3=Copy(CommentLine,1,Length(Five3)) Then
  551.           Begin Delete(CommentLine,1,Length(Five3)); Size:=5 End
  552.         Else
  553.         If Six3=Copy(CommentLine,1,Length(Six3)) Then
  554.           Begin Delete(CommentLine,1,Length(Six3)); Size:=6 End
  555.         Else
  556.         If Seven3=Copy(CommentLine,1,Length(Seven3)) Then
  557.           Begin Delete(CommentLine,1,Length(Seven3)); Size:=7 End
  558.         Else
  559.           {Unknown run-time parameter}
  560.           {Terminate prematurely current scan}
  561.           CommentLine:='%'
  562.         End;
  563.       {Echo status if allowed}
  564.       If Echo And (CommentLine<>'%') Then
  565.         Begin
  566.         Write(OutFile,'%');
  567.         EchoParameters(OutFile,RunTime)
  568.         End
  569.       End
  570.     Else
  571.       {Unknown run-time parameter flag}
  572.       {Terminate prematurely current scan}
  573.       CommentLine:='%'
  574.   Until Length(CommentLine)=1
  575.   End
  576. End;
  577.  
  578. Procedure LineBreak(Var OutFile:OutFileType; ExtraSpace:Boolean;
  579.                     Var Scanning:ScanningType);
  580. {The continuous chain of Bitmaps has just been interrupted by a line break}
  581. {We know the next Roman character is equivalent to a space, i.e. not a letter}
  582. {A \eeee may be inserted if the previous Bitmap was a .,!?}
  583. {A \eee may be inserted if the previous Bitmap was a :; center dot )]'"}
  584. {If glue inserted, make sure to leave a totally blank line as present before}
  585. Begin
  586. With Scanning Do
  587.   Begin
  588.   Immediate:=False;
  589.   If Echo And ExtraSpace Then 
  590.     If RomanMajorEOL Then Writeln(OutFile,'\eeee')
  591.     Else
  592.       If RomanMinorEOL Then Writeln(OutFile,'\eee')
  593.   End
  594. End;
  595.  
  596. Procedure RomanBreak(Var OutFile:OutFileType; ExtraSpace:Boolean;
  597.                      Var Scanning:ScanningType);
  598. {The continuous chain of Bitmaps has just been interrupted by a Roman}
  599. {The next Roman character may be a letter so a \eee is possible}
  600. {A \eeee may be inserted if the previous Bitmap was a .,!?}
  601. {A \eee may be inserted if the previous Bitmap was a :; center dot )]'"}
  602. {Curly brackets are used in \eee and \eeee when the next Roman is a letter}
  603. Begin
  604. With Scanning Do
  605.   Begin
  606.   Immediate:=False;
  607.   If Echo And ExtraSpace Then
  608.     If RomanMajorEOL Then
  609.       If WasLetter Then Write(OutFile,'\eeee{}')
  610.       Else Write(OutFile,'\eeee')
  611.     Else
  612.       If RomanMinorEOL Then
  613.         If WasLetter Then Write(OutFile,'\eee{}')
  614.         Else Write(OutFile,'\eee')
  615.       Else
  616.         If WasLetter And Not RomanOpening Then Write(OutFile,'\eee{}')
  617.   End
  618. End;
  619.  
  620. Procedure GotUNIX(Var OutFile:OutFileType; Var Scanning:ScanningType;
  621.                   Var RunTime:RunTimeType);
  622. {Handles UNIX EOL}
  623. {May add glue after the previous Bitmap and before this Roman}
  624. Begin
  625. With Scanning,RunTime Do
  626.   Begin
  627.   If Immediate Then
  628.     If First Then LineBreak(OutFile,ExtraSpace,Scanning)
  629.     Else
  630.       If Not Comment Then
  631.         If Percent Then
  632.           If Echo Then Write(OutFile,'%') 
  633.           Else
  634.         Else
  635.           LineBreak(OutFile,ExtraSpace,Scanning);
  636.   If Echo Then Writeln(OutFile);
  637.   If Comment Then 
  638.     If Not First Then PerformScan(CommentLine,RunTime,Echo,OutFile)
  639.     Else
  640.   Else
  641.     WasLetter:=False;
  642.   First:=True;
  643.   Comment:=True;
  644.   CommentLine:=''
  645.   End
  646. End;
  647.  
  648. Procedure GotDOS(Var OutFile:OutFileType; Var Scanning:ScanningType;
  649.                  Var RunTime:RunTimeType; Var InFile:InFileType);
  650. {Handles DOS EOL}
  651. {May add glue after the previous Bitmap and before this Roman}
  652. {An error only stops the current pass to help the user determine its cause}
  653. Var Data2:Byte;
  654. Begin
  655. With Scanning Do
  656.   Begin
  657.   GotUNIX(OutFile,Scanning,RunTime);
  658.   {Line Feed must follow immediately}
  659.   If EOF(InFile) Then Done:=True
  660.   Else
  661.     Begin
  662.     Read(InFile,Data2);
  663.     If Data2<>$0A Then Done:=True
  664.     End;
  665.   If Done Then
  666.     Begin
  667.     Writeln('.');
  668.     Write(Chr(7)+'Abnormal DOS end of line..')
  669.     End
  670.   End
  671. End;
  672.  
  673. Procedure ValidateBitmap(Bitmap:BitmapRange);
  674. {Prints a warning when an extended or an empty Bitmap is used}
  675. Var Invalid:Boolean;
  676. Begin
  677. Invalid:=False;
  678. If (109<=Bitmap) And (Bitmap<=119) Then Invalid:=True
  679. Else
  680. If (128<=Bitmap) And (Bitmap<=135) Then Invalid:=True
  681. Else
  682. If (143<=Bitmap) And (Bitmap<=153) Then Invalid:=True
  683. Else
  684. If (169<=Bitmap) And (Bitmap<=175) Then Invalid:=True
  685. Else
  686. If (184<=Bitmap) And (Bitmap<=203) Then Invalid:=True
  687. Else
  688. If (214<=Bitmap) And (Bitmap<=220) Then Invalid:=True
  689. Else
  690. If (247<=Bitmap) And (Bitmap<=252) Then Invalid:=True
  691. Else
  692. If (279<=Bitmap) And (Bitmap<=282) Then Invalid:=True
  693. Else
  694. If Bitmap=366 Then Invalid:=True
  695. Else
  696. If (463<=Bitmap) And (Bitmap<=470) Then Invalid:=True
  697. Else
  698. If (495<=Bitmap) And (Bitmap<=502) Then Invalid:=True
  699. Else
  700. If (527<=Bitmap) And (Bitmap<=564) Then Invalid:=True
  701. Else
  702. If (598<=Bitmap) And (Bitmap<=612) Then Invalid:=True
  703. Else
  704. If (646<=Bitmap) And (Bitmap<=658) Then Invalid:=True
  705. Else
  706. If (691<=Bitmap) And (Bitmap<=1410) Then Invalid:=True
  707. Else
  708. If (4376<=Bitmap) And (Bitmap<=4418) Then Invalid:=True;
  709. If Invalid Then
  710.   Begin
  711.   Writeln('.');
  712.   Write('Warning! The non-standard JIS ''83 Bitmap ',Bitmap,' encountered')
  713.   End
  714. End;
  715.  
  716. Procedure GotBitmap(Var OutFile:OutFileType; EUC,Extended:Boolean; 
  717.                     Var InFile:InFileType; Var Scanning:ScanningType); 
  718. {Handles Bitmap}
  719. {An error only stops the current pass to help the user determine its cause}
  720. {If desired, non-standard Bitmaps are pointed out in the first pass}
  721. Var Data2:Byte;
  722. Begin
  723. With Scanning Do
  724.   Begin
  725.   If First Then
  726.     {First character on line}
  727.     Begin
  728.     First:=False;
  729.     Comment:=False
  730.     End;
  731.   If EOF(InFile) Then
  732.     Begin
  733.     Done:=True;
  734.     Writeln('.');
  735.     If EUC Then Write(Chr(7)+'Incomplete EUC character pair..')
  736.     Else Write(Chr(7)+'Incomplete MS-kanji character pair..')
  737.     End
  738.   Else
  739.     Begin
  740.     Read(InFile,Data2);
  741.     If EUC Then
  742.       If ($A0<Data2) And (Data2<$FF) Then 
  743.         Bitmap:=94*(Data1-$A1)+(Data2-$A1)+1
  744.       Else
  745.         Begin
  746.         Done:=True;
  747.         Writeln('.');
  748.         Write(Chr(7)+'Invalid EUC character pair..')
  749.         End
  750.     Else
  751.       If ( ($40<=Data2) And (Data2<=$7E) ) Or 
  752.          ( ($80<=Data2) And (Data2<=$FC) )
  753.       Then
  754.         Begin
  755.         If (Data1>=$E0) Then Bitmap:=1+188*(Data1-$C1)
  756.         Else Bitmap:=1+188*(Data1-$81);
  757.         If (Data2>=$80) Then Bitmap:=Bitmap+(Data2-$41)
  758.         Else Bitmap:=Bitmap+(Data2-$40)
  759.         End
  760.       Else
  761.         Begin
  762.         Done:=True;
  763.         Writeln('.');
  764.         Write(Chr(7)+'Invalid MS-kanji character pair..')
  765.         End;
  766.     If Not Done Then
  767.       {Bitmaps in comment skipped}
  768.       If Comment Then
  769.         Begin
  770.         CommentLine:=CommentLine+Chr(Data1)+Chr(Data2);
  771.         If Echo Then Write(OutFile,Chr(Data1)+Chr(Data2))
  772.         End
  773.       Else
  774.         If (1<=Bitmap) And (Bitmap<=BitmapMax) Then 
  775.           Begin
  776.           Found:=True;
  777.           {Point out non-standard Bitmaps in first pass}
  778.           If Not Echo And Not Extended Then ValidateBitmap(Bitmap)
  779.           End
  780.         Else
  781.           Begin
  782.           Done:=True;
  783.           Writeln('.');
  784.           Write(Chr(7)+'Bitmap ',Bitmap,' does not exist..')
  785.           End
  786.     End
  787.   End
  788. End;
  789.  
  790. Procedure GotRoman(Var OutFile:OutFileType; ExtraSpace:Boolean;
  791.                    Var Scanning:ScanningType);
  792. {Handles roman}
  793. {May add glue after the previous Bitmap and before this Roman}
  794. Begin
  795. With Scanning Do
  796.   Begin
  797.   If First Then
  798.     {First character on line}
  799.     Begin
  800.     First:=False;
  801.     If Chr(Data1)<>'%' Then Comment:=False
  802.     End;
  803.   If Comment Then CommentLine:=CommentLine+Chr(Data1)
  804.   Else
  805.     Begin
  806.     {Determine if this roman is a letter or a number}
  807.     WasLetter:=( ('A'<=UpCase(Chr(Data1))) And (UpCase(Chr(Data1))<='Z') ) Or
  808.                       (  ('0'<=Chr(Data1)) And (Chr(Data1)<='9') );
  809.     If Immediate Then RomanBreak(OutFile,ExtraSpace,Scanning)
  810.     End;
  811.   If Echo Then Write(OutFile,Chr(Data1))
  812.   End
  813. End;
  814.  
  815. Procedure GetBitmap(Var InFile:InFileType; Var OutFile:OutFileType; 
  816.                     Var Scanning:ScanningType; Var RunTime:RunTimeType);
  817. {Scans input file and stops when a Bitmap is met}
  818. {An error only stops the current pass to help the user determine its cause}
  819. {Accepts UNIX LF or DOS CR/LF as end of line indicator in input file}
  820. {Updates JemTeX parameters with run-time parameters}
  821. {Comment indicates the line is a comment line and does not break continuity}
  822. {Immediate indicates the current Bitmap immediately followed previous Bitmap}
  823. {If the next character encountered is Roman, glue may be inserted}
  824. {If desired, will add % at Japanese end of lines to preserve continuity}
  825. Begin
  826. With Scanning,RunTime Do
  827.   Begin
  828.   {No Bitmap found initially}
  829.   Found:=False;
  830.   {Assume the next character is a Bitmap}
  831.   WasLetter:=False; 
  832.   Immediate:=True;
  833.   {Some non-comment Bitmap was met before or it's the first call to GetBitmap}
  834.   CommentLine:='';
  835.   {Comment holds; it's the first call ever to GetBitmap; it's first character}
  836.   {Comment fails; some non-comment Bitmap was met before; it isnt 1st character}
  837.   First:=Comment;
  838.   Repeat
  839.     {Check if file just finished}
  840.     If EOF(InFile) Then Done:=True
  841.     Else
  842.       {More file coming}
  843.       Begin
  844.       Read(InFile,Data1);
  845.       If Data1=$0A Then GotUNIX(OutFile,Scanning,RunTime)
  846.       Else
  847.         If Data1=$0D Then GotDOS(OutFile,Scanning,RunTime,InFile)
  848.         Else
  849.           If EUC Then
  850.             If ($A0<Data1) And (Data1<$FF) Then
  851.               GotBitmap(OutFile,EUC,Extended,InFile,Scanning)
  852.             Else
  853.               GotRoman(OutFile,ExtraSpace,Scanning)
  854.           Else
  855.             If ( ($81<=Data1) And (Data1<=$9F) ) Or 
  856.                ( ($E0<=Data1) And (Data1<=$EA) ) 
  857.             Then
  858.               GotBitmap(OutFile,EUC,Extended,InFile,Scanning)
  859.             Else
  860.               GotRoman(OutFile,ExtraSpace,Scanning)
  861.       End
  862.   Until Done Or Found
  863.   End
  864. End;
  865.  
  866. {---------------------------------- GetFont ----------------------------------}
  867.  
  868. Procedure GetFont(Var InFile:InFileType; Var Fonts:FontsType; 
  869.                   Var InitialRunTime:RunTimeType);
  870. {Finds the Japanese fonts needed}
  871. Var 
  872.   {Run time parameters}
  873.   RunTime:RunTimeType;
  874.   {Current font number}
  875.   FontPtr:FontRange;
  876.   SizePtr:SizeRange;
  877.   {Scanning information}
  878.   Scanning:ScanningType;
  879.   {Dummy since no output in first pass}
  880.   DummyOutFile:OutFileType;
  881. Begin
  882. RunTime:=InitialRunTime;
  883. {No Japanese font needed so far}
  884. For SizePtr:=1 To SizeMax Do 
  885.   For FontPtr:=0 To FontMax Do
  886.     Fonts[SizePtr,FontPtr]:=False;
  887. With Scanning Do
  888.   Begin
  889.   {Not reached EOF yet}
  890.   Done:=False;
  891.   {No echo in first pass}
  892.   Echo:=False;
  893.   {Dummy since no output in first pass}
  894.   Immediate:=False;
  895.   WasLetter:=False;
  896.   RomanMajorEOL:=False;
  897.   RomanMinorEOL:=False;
  898.   RomanOpening:=False;
  899.   {Tell indirectly to GetBitmap that this is the first time it is called}
  900.   Comment:=True;
  901.   Repeat
  902.     {Get the next Bitmap skipping over [La]TeX comments}
  903.     GetBitmap(InFile,DummyOutFile,Scanning,RunTime);
  904.     If Not Done Then Fonts[RunTime.Size,Bitmap Div 128]:=True
  905.   Until Done
  906.   End;
  907. {Last state of LaTeX prevails for the second pass}
  908. InitialRunTime.LaTeX:=RunTime.LaTeX
  909. End;
  910.  
  911. {----------------------------------- Header ----------------------------------}
  912.  
  913. Procedure Header(Var OutFile:OutFileType; Var Fonts:FontsType; LaTeX:Boolean);
  914. {Writes [La]TeX header}
  915. {Fonts declared global for speed, even if never actually modified here}
  916. Var 
  917.   FontPtr:FontRange;
  918.   SizePtr:SizeRange;
  919.   C0,C1,C2:Char;
  920.   Scale:Integer;
  921. Begin
  922. Writeln(OutFile,'\tracingstats=1');
  923. For SizePtr:=1 To SizeMax Do
  924.   Begin
  925.   C0:=Chr( Ord('a')+SizePtr-1 );
  926.   Case SizePtr Of
  927.     1:Scale:=1000;
  928.     2:Scale:=1095;
  929.     3:Scale:=1200;
  930.     4:Scale:=1440;
  931.     5:Scale:=1728;
  932.     6:Scale:=2074;
  933.     7:Scale:=2488
  934.     End;
  935.   For FontPtr:=0 To FontMax Do
  936.     If Fonts[SizePtr,FontPtr] Then
  937.       Begin
  938.       C1:=Chr( Ord('a')+(FontPtr Div 8) );
  939.       C2:=Chr( Ord('a')+(FontPtr Mod 8) );
  940.       If LaTeX Then
  941.         Writeln(OutFile,'\newfont{\k'+C0+C1+C2+'}{kanji'+C1+C2+' scaled ',
  942.                 Scale,'}')
  943.       Else
  944.         Writeln(OutFile,'\font\k'+C0+C1+C2+'=kanji'+C1+C2+' scaled ',Scale)
  945.     End
  946.   End;
  947. If LaTeX Then
  948.   Begin
  949.   Writeln(OutFile,'\newcommand{\kk}[2]{{#1\symbol{#2}}}');
  950.   Writeln(OutFile,'\newcommand{\hh}{\discretionary{}{}{}}');
  951.   Writeln(OutFile,'\newcommand{\ee}{\nobreak\hskip0pt plus.1em\relax}');
  952.   Writeln(OutFile,'\newcommand{\eee}{\nobreak\hskip.3em plus.1em\relax}');
  953.   Writeln(OutFile,'\newcommand{\eeee}{\nobreak\hskip.9em plus.1em minus.1em}')
  954.   End
  955. Else
  956.   Begin
  957.   Writeln(OutFile,'\def\kk#1#2{{#1\char#2}}');
  958.   Writeln(OutFile,'\def\hh{\discretionary{}{}{}}');
  959.   Writeln(OutFile,'\def\ee{\nobreak\hskip0pt plus.1em\relax}');
  960.   Writeln(OutFile,'\def\eee{\nobreak\hskip.3em plus.1em\relax}');
  961.   Writeln(OutFile,'\def\eeee{\nobreak\hskip.9em plus.1em minus.1em}')
  962.   End;
  963. Writeln(OutFile)
  964. End;
  965.  
  966. {---------------------------------- Convert ----------------------------------}
  967.  
  968. Procedure BitmapType(Bitmap:BitmapRange; Var Punctuation:PunctuationType);
  969. {Finds characteristics of current Bitmap}
  970. Begin
  971. With Punctuation Do
  972.   Begin
  973.   OldMajorEOL:=NewMajorEOL;
  974.   OldMinorEOL:=NewMinorEOL;
  975.   OldOpening:=NewOpening;
  976.   OldClosing:=NewClosing;
  977.   OldCenterDot:=NewCenterDot;
  978.   OldJapanese:=NewJapanese;
  979.   NewMajorEOL:=False;
  980.   NewMinorEOL:=False;
  981.   NewOpening:=False;
  982.   NewClosing:=False;
  983.   NewCenterDot:=False;
  984.   NewJapanese:=False;
  985.   {Full width .,!?}
  986.   If (2<=Bitmap) And (Bitmap<=5) Then NewMajorEOL:=True
  987.   Else
  988.   If (Bitmap=9) Or (Bitmap=10) Then NewMajorEOL:=True
  989.   Else
  990.   {Half width .,!?}
  991.   If (Bitmap=691) Or (Bitmap=720) Then NewMajorEOL:=True
  992.   Else
  993.   {Full width :;}
  994.   If (Bitmap=7) Or (Bitmap=8) Then NewMinorEOL:=True
  995.   Else
  996.   {Half width :;}
  997.   If (Bitmap=692) Or (Bitmap=693) Then NewMinorEOL:=True
  998.   Else
  999.   {Full width `"([< and other openings}
  1000.   If (38<=Bitmap) And (Bitmap<=58) And Not Odd(Bitmap) Then NewOpening:=True
  1001.   Else
  1002.   {Half width `"([< and other openings}
  1003.   If (696<=Bitmap)And(Bitmap<=716) And Not Odd(Bitmap) Then NewOpening:=True
  1004.   Else
  1005.   {Full width '")]> and other closings}
  1006.   If (39<=Bitmap) And (Bitmap<=59) And Odd(Bitmap) Then NewClosing:=True
  1007.   Else
  1008.   {Half width '")]> and other closings}
  1009.   If (697<=Bitmap) And (Bitmap<=717) And Odd(Bitmap) Then NewClosing:=True
  1010.   Else
  1011.   {Full width Japanese center dot}
  1012.   If (Bitmap=6) Then NewCenterDot:=True
  1013.   Else
  1014.   {Half width Japanese center dot}
  1015.   If (Bitmap=469) Then NewCenterDot:=True
  1016.   Else
  1017.   {Full width Hiragana}
  1018.   If (283<=Bitmap) And (Bitmap<=365) Then NewJapanese:=True
  1019.   Else
  1020.   {Full width Katakana}
  1021.   If (377<=Bitmap) And (Bitmap<=462) Then NewJapanese:=True
  1022.   Else
  1023.   {Full width Kanji level 1}
  1024.   If (1411<=Bitmap) And (Bitmap<=4375) Then NewJapanese:=True
  1025.   Else
  1026.   {Full width Kanji level 2}
  1027.   If (4419<=Bitmap) And (Bitmap<=7806) Then NewJapanese:=True
  1028.   Else
  1029.   {Script Hiragana}
  1030.   If (753<=Bitmap) And (Bitmap<=835) Then NewJapanese:=True
  1031.   Else
  1032.   {Script Katakana}
  1033.   If (847<=Bitmap) And (Bitmap<=932) Then NewJapanese:=True
  1034.   End
  1035. End;
  1036.  
  1037. Procedure Hyphenate(Var OutFile:OutFileType; Var Punctuation:PunctuationType);
  1038. {Adds hyphenation between consecutive Bitmaps}
  1039. Begin
  1040. With Punctuation Do
  1041.   {No hyphenation between two odd symbols}
  1042.   If OldJapanese Or NewJapanese Then
  1043.     {No hyphenation before some symbols}
  1044.     If Not NewMajorEOL And Not NewMinorEOL And Not NewCenterDot And 
  1045.        Not NewClosing
  1046.     Then   
  1047.       {No hyphenation after some symbols}
  1048.       If Not OldOpening Then Write(OutFile,'\hh')
  1049. End;
  1050.  
  1051. Procedure Glue(Var OutFile:OutFileType; Var Punctuation:PunctuationType;
  1052.                ExtraSpace:Boolean);
  1053. {Adds glue between consecutive Bitmaps}
  1054. Var GlueAdded:Boolean;
  1055. Begin
  1056. With Punctuation Do
  1057.   Begin
  1058.   GlueAdded:=False;
  1059.   If ExtraSpace Then
  1060.     Begin
  1061.     {Trying to add big glue}
  1062.     If OldMajorEOL Then
  1063.       {No big glue between identical symbols}
  1064.       If Not NewMajorEOL Then
  1065.         {No big glue before some symbols}
  1066.         If Not NewClosing Then
  1067.           Begin
  1068.           GlueAdded:=True;
  1069.           Write(OutFile,'\eeee')
  1070.           End;
  1071.     If Not GlueAdded Then
  1072.       {Trying to add medium glue based on old symbol}
  1073.       If OldMinorEOL Or OldCenterDot Or OldClosing Then
  1074.         {No medium glue before some symbols}
  1075.         If Not NewMajorEOL And Not NewMinorEOL And Not NewClosing Then
  1076.           Begin
  1077.           GlueAdded:=True;
  1078.           Write(OutFile,'\eee')
  1079.           End;
  1080.     If Not GlueAdded Then
  1081.       {Trying to add medium glue based on new symbol}
  1082.       If NewCenterDot Or NewOpening Then
  1083.         {No medium glue after some symbols}
  1084.         If Not OldOpening Then
  1085.           Begin
  1086.           GlueAdded:=True;
  1087.           Write(OutFile,'\eee')
  1088.           End
  1089.     End;
  1090.   {Always make sure to add some glue}
  1091.   If Not GlueAdded Then Write(OutFile,'\ee')
  1092.   End
  1093. End;
  1094.  
  1095. Procedure Convert(Var InFile:InFileType; Var OutFile:OutFileType;
  1096.                   Var RunTime:RunTimeType);
  1097. {Convert .JEM into .TeX by translating Bitmaps and adding hyphenation and glue}
  1098. Var 
  1099.   {Japanese punctuation information}
  1100.   Punctuation:PunctuationType;
  1101.   {Scanning information}
  1102.   Scanning:ScanningType;
  1103.   {Current font number}
  1104.   FontPtr:FontRange;
  1105.   C0,C1,C2:Char;
  1106. Begin
  1107. With Punctuation,Scanning,RunTime Do
  1108.   Begin
  1109.   {Not reached EOF yet}
  1110.   Done:=False;
  1111.   {Echo in second pass}
  1112.   Echo:=True;
  1113.   {Nothing done yet}
  1114.   Immediate:=False;
  1115.   WasLetter:=False;
  1116.   {Tell indirectly to GetBitmap that this is the first time it is called}
  1117.   Comment:=True;
  1118.   {Initial japanese punctuation information}
  1119.   NewMajorEOL:=False; NewMinorEOL:=False;
  1120.   NewOpening:=False; NewClosing:=False;
  1121.   NewCenterDot:=False; NewJapanese:=False;
  1122.   Repeat
  1123.     {Set up scanning information in case a roman letter follows immediately}
  1124.     RomanMajorEOL:=NewMajorEOL;
  1125.     RomanMinorEOL:=NewMinorEOL Or NewCenterDot Or NewClosing;
  1126.     RomanOpening:=NewOpening;
  1127.     {Get the next Bitmap skipping over [La]TeX comments}
  1128.     {May add glue between the old Bitmap and an hypothetical Roman}
  1129.     GetBitmap(InFile,OutFile,Scanning,RunTime);
  1130.     If Not Done Then
  1131.       Begin
  1132.       {Find what kind of Bitmap it is}
  1133.       BitmapType(Bitmap,Punctuation);
  1134.       If Immediate Then
  1135.         {Add hyphenation and glue between consecutive Bitmaps}
  1136.         Begin
  1137.         Hyphenate(OutFile,Punctuation);
  1138.         Glue(OutFile,Punctuation,ExtraSpace)
  1139.         End
  1140.       Else
  1141.         {Add glue after the old Roman and before this new Bitmap}
  1142.         If ExtraSpace Then
  1143.           If NewCenterDot Or NewOpening Then Write(OutFile,'\eee')
  1144.           Else 
  1145.             If WasLetter Then
  1146.               {No medium glue before some symbols}
  1147.               If Not NewMajorEOL And Not NewMinorEOL And Not NewClosing Then
  1148.                 Write(OutFile,'\eee');
  1149.       {Write the Bitmap}
  1150.       C0:=Chr( Ord('a')+Size-1 );
  1151.       FontPtr:=Bitmap Div 128;
  1152.       C1:=Chr( Ord('a')+(FontPtr Div 8) );
  1153.       C2:=Chr( Ord('a')+(FontPtr Mod 8) );
  1154.       Write(OutFile,'\kk{\k'+C0+C1+C2+'}{',Bitmap Mod 128,'}')
  1155.       {The next character may be Roman, GetBitmap will handle the glue then}
  1156.       End
  1157.   Until Done
  1158.   End
  1159. End;
  1160.  
  1161. {------------------------------------ Main -----------------------------------}
  1162.  
  1163. Begin
  1164. Writeln;
  1165. Writeln('Japanese to [La]TeX Conversion Program.');   {To make Borland happy}
  1166. Writeln('Version 2.00 Copyright F. Jalbert 1991.');
  1167. Writeln;
  1168.  
  1169.  
  1170. GetParameters(RunTime);
  1171. Writeln;
  1172. Write('Opening Japanese file '+RunTime.FileName);
  1173. OpenFile(InFile,RunTime);
  1174. Writeln('.');
  1175. If RunTime.LaTeX Then Write('Creating LaTeX file '+RunTime.FileName+'.tex')
  1176. Else Write('Creating TeX file '+RunTime.FileName+'.tex');
  1177. Assign(OutFile,RunTime.FileName+'.tex');
  1178. Rewrite(OutFile);
  1179. Writeln('.');
  1180. Writeln;
  1181.  
  1182.  
  1183. Write('Scanning Japanese file for fonts');
  1184. GetFont(InFile,Fonts,RunTime);
  1185. Reset(InFile);
  1186. Writeln('.');
  1187. If RunTime.LaTeX Then Write('Writing LaTeX header')
  1188. Else Write('Writing TeX header');
  1189. Header(OutFile,Fonts,RunTime.LaTeX);
  1190. Writeln('.');
  1191. Write('Converting Japanese file');
  1192. Convert(InFile,OutFile,RunTime);
  1193. Writeln('.');
  1194. Writeln;
  1195.  
  1196.  
  1197. Write('Closing Japanese file '+RunTime.FileName+RunTime.Extension);
  1198. Close(InFile);
  1199. Writeln('.');
  1200. If RunTime.LaTeX Then Write('Closing LaTeX file '+RunTime.FileName+'.tex')
  1201. Else Write('Closing TeX file '+RunTime.FileName+'.tex');
  1202. Close(OutFile);
  1203. Writeln('.');
  1204. Writeln;
  1205.  
  1206.  
  1207. Writeln('Japanese to [La]TeX conversion completed.');
  1208. Writeln
  1209. End.
  1210.